package com.hhit.collaborative_learning.learning;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hhit.collaborative_learning.dao.impl.PublicDaoImplMySql;
import com.hhit.collaborative_learning.utils.Utils;

public class ManageBlogServlrt extends HttpServlet {
//0 舍弃  1 置顶   2 删除  3  彻底删除  4 解锁   5 锁定  6删除评论  7增加阅读量  8精华
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String action=request.getParameter("action");
		String blogId=request.getParameter("blogId");
		String comId=request.getParameter("comId");
		String hasRight=request.getParameter("right");
//		System.out.println(action+";"+blogId);
		PublicDaoImplMySql dao=new PublicDaoImplMySql();
		PrintWriter out=response.getWriter();
		if(action.equals("1")){
			String userId=Utils.getCookieValue("userId", request);
			if(hasRight!=null){
				out.print(dao.setTop(Integer.parseInt(blogId),Integer.parseInt(userId),true));
			}else{
				out.print(dao.setTop(Integer.parseInt(blogId),Integer.parseInt(userId),false));
			}
		}else if(action.equals("3")){
			dao.deleteCompletely(Integer.parseInt(blogId));
		}else if(action.equals("4")||action.equals("5")){
			dao.manageBlog(action, Integer.parseInt(blogId));
			request.getRequestDispatcher("learning/bloglist.jsp").forward(request, response);
		}else if(action.equals("6")){
			out.print(dao.deleteComment(Integer.parseInt(comId),Integer.parseInt(blogId)));
		}else if(action.equals("7")){
			out.print(dao.manageBlog(action, Integer.parseInt(blogId)));
		}else if(action.equals("8")){
			out.print(dao.setPrime(Integer.parseInt(blogId)));
		}
		else{
			dao.manageBlog(action, Integer.parseInt(blogId));
		}
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
